package com.ggh.jinjilive.ui.home.video;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.home.live.LiveCategory;
import com.ggh.jinjilive.mobile.home.video.VideoList;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class VideoViewModel extends BaseViewModel {
    //视频类目列表
    public MutableLiveData<List<LiveCategory>> listMutableLiveData = new MutableLiveData<>();
    //娱乐 带货 红人 热门 才艺 游戏 体育
    public ObservableField<String> category_id = new ObservableField<>("1");
    //视频列表
    public MutableLiveData<List<VideoList>> liveData = new MutableLiveData<>();

    public VideoViewModel(SystemApiService apiCallInterface) {

        super(apiCallInterface);
    }

    /**
     * 视频分类
     */
    public void VideoCategory(){
        addSubscribe(apiCallInterface.VideoCategory().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<LiveCategory>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<LiveCategory> liveCategoryList = (List<LiveCategory>) resultEntity.getData();
                listMutableLiveData.setValue(liveCategoryList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }

    /**
     * 获取视屏列表
     */
    public void videoList(){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("category_id",category_id.get());
        paramsa.put("page",page +"");
        paramsa.put("limit",pageSize);
        addSubscribe(apiCallInterface.videoList(paramsa).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<LiveCategory>>>() {
                    @Override
                    public void onNextData(ResultEntity resultEntity) {
                        List<VideoList> videoListList = (List<VideoList>) resultEntity.getData();
                        liveData.setValue(videoListList);
                    }

                    @Override
                    public void onErrorNet(Throwable t, String netMsg) {

                    }
                }));
    }
}
